﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAL
{
    public partial class Booking
    {
        public List<string> getBookedTimeSlots(DAL.Booking book)
        {
            DAL.ClubEntities club = new DAL.ClubEntities();
            var bookTimeQuery = from o in club.Bookings
                                where o.FacilityId == book.FacilityId && o.BookingDate == book.BookingDate
                                orderby o.BookingTime ascending
                                select o.BookingTime;
            List<string> timeSlots = bookTimeQuery.ToList<string>();
            return timeSlots;
        }
        public List<DAL.Booking> getAllBookings()
        {
            DAL.ClubEntities club = new DAL.ClubEntities();
            var bookingQuery = from o in club.Bookings
                               orderby o.BookingDate, o.BookingTime
                               select o;
            return bookingQuery.ToList<DAL.Booking>();
        }
        public List<DAL.Booking> getBookingsByUser(DAL.User user)
        {
            DAL.ClubEntities club = new DAL.ClubEntities();
            var bookingQuery = from o in club.Bookings
                               where o.UserId == user.Id
                               orderby o.BookingDate, o.BookingTime
                               select o;
            return bookingQuery.ToList<DAL.Booking>();
        }
        public void cancelBooking(DAL.Booking book)
        {
            DAL.ClubEntities club = new DAL.ClubEntities();
            var bookingQuery = from o in club.Bookings
                               where o.Id == book.Id
                               select o;
            club.Bookings.DeleteObject(bookingQuery.First<DAL.Booking>());
            club.SaveChanges();
        }
    }
}
